﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;

using easyList.Entities;

namespace easyList.IO.Writer
{
    class TXTWriter
    {

        static TXTWriter instance = null;
        static readonly object padlock = new object();

        TXTWriter() { }
        public static TXTWriter Instance
        {
            get
            {
                lock (padlock)
                {
                    if (instance == null)
                    {
                        instance = new TXTWriter();
                    }
                    return instance;
                }
            }
        }

       public void writeTXT(ArchiveObject archive, string destinationpath)
        {

            TextWriter tw = new StreamWriter(destinationpath);

            tw.WriteLine("Archivelist created, " + DateTime.Now);
            tw.WriteLine("----------------------------");

           
            // write a line of text to the file
            foreach (FileObject currentFile in archive.contentList)
            {
                tw.WriteLine(currentFile.filename + " || " + currentFile.storeID);

            }

            // close the stream
            tw.Close();


        }

       public void writeTXT(string formattedContent)
       {
           string path;
           path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

           string p = new Uri(path).LocalPath;

           TextWriter tw = new StreamWriter(p + "\\easyList.cfg");
          

           tw.WriteLine(formattedContent);

           // close the stream
           tw.Close();


       }

    }
}
